<template>
  <div>
    <h1>回调页面，请扫描二维码登录</h1>
  </div>
</template>

<script>
import { getUserQQinfo, getUserQQlogin } from '@/http/index.js'
import { mapMutations } from 'vuex'
export default {
  created() {
    this.getQQAccessToken()
  },
  methods: {
    ...mapMutations(['setToken']),
    getQQAccessToken() {
      const isLogin = this.$QQ.Login.check()
      if (isLogin) {
        this.$QQ.Login.getMe((openId, accessToken) => {
          const tempParams = {
            openid: openId,
            access_token: accessToken,
            oauth_consumer_key: '101850878', // appId
          }
          getUserQQinfo(tempParams, (res) => {
            // console.log(res)
            const tempPar = {
              openid: openId,
              username: res.data.nickname,
            }
            getUserQQlogin(tempPar, (res) => {
              // console.log(res)
              this.setToken({ token: res.data.token })
              // 登录完成 触发 获取用户信息
              this.$store.dispatch('getInfo')
              this.$store.dispatch('getCarDataList')
              this.$router.push('/user')
            })
          })
        })
      }
    },
  },
}
</script>

<style lang="scss" scoped></style>
